<template>
    <div class="photoinfo-container">
        <h3>{{ photoinfo.title }}</h3>
        <p class="subtitle">
            <span>发表时间：{{ photoinfo.add_time | dateFormat }}</span>
            <span>点击：{{ photoinfo.click }}次</span>
        </p>
        <hr>
        <!-- 缩略图区域 -->
        <div class="thumbs">
            <vue-preview :slides="list" @close="handleClose"></vue-preview>
        </div>        
        <!-- <img class="preview-img" v-for="(item, index) in list" :key="item.src" :src="item.src" height="100" @click="$preview.open(index, list)"> -->
        <!-- 图片内容区域 -->
        <div class="content" v-html="photoinfo.content"></div>
        <!-- 现成的评论子组件 -->
        <cmt-box :id="id"></cmt-box>
    </div>
</template>

<script>
//导入评论子组件
import comment from '../subcomponents/comment.vue'
import { Toast } from 'mint-ui' 

export default {
    data(){
        return {
            id: this.$route.params.id,   //从路由中获取图片id
            // photoinfo: {},
            photoinfo: {
                title: "邮电局的闪光时刻",
                add_time: Date.now(),
                click: 21,
                content: "我还是相信，星星会说话，石头会开花，穿过夏天的木栅栏和冬天的风雪过后，<strong>你</strong>终将抵达。"
            },
            // list: []  //缩略图的数组
            list: [
                { src: require("../../images/Photo/3.jpg") },
                { src: require("../../images/Photo/4.jpg") },
                { src: require("../../images/Photo/13.jpg") },
                { src: require("../../images/Photo/17.jpg") }
            ]
        };
    },
    created(){
        // this.getPhotoInfo();
        this.getThumbs();
    },
    methods: {
        // getPhotoInfo(){  //获取图片的详情
        //     this.$http.get('api/getimageInfo/' + this.id).then(result => {
        //         if(result.body.status === 0){
        //             this.photoinfo = result.body.message[0];
        //         }
        //     })
        // },
        // getThumbs(){  //获取服务器缩略图
        //     this.$http.get('api/getthumimages/' + this.id).then(result => {
        //         if(result.body.status === 0){
        //             //循环每个图片数据，补全图片的宽和高
        //             result.body.message.forEach(item => {
        //                 item.w = 600;
        //                 item.h = 400;
        //             });
        //             //完整数据保存到list中
        //             this.list = result.body.message;
        //         }
        //     });
        // }
        getThumbs(){
            this.list.forEach(item => {
                item.w = 600;  //大图浏览时的宽度
                item.h = 400;  //大图浏览时的高度
                item.msrc = item.src;  //小图
            });
        },
        handleClose(){
            Toast("关闭缩略图！")
        }
    },
    components: {  //注册评论子组件
        'cmt-box': comment
    }
}
</script>

<style lang="scss">
.photoinfo-container{
    padding: 3px;
    h3{
        color: #26A2FF;
        font-size: 15px;
        text-align: center;
        margin: 15px 0;
    }
    .subtitle{
        display: flex;
        justify-content: space-between;
        font-size: 13px;
    }
    .thumbs{
        /deep/ .my-gallery{
            display:flex;
            flex-wrap:wrap;
            figure{
                width:30%;
                margin:10px;
                img{
                    width:100%;
                    box-shadow: 0 0 8px #999;
                }
            }
        }
    }
    .content{
        font-size: 13px;
        line-height: 30px;
    }
}
</style>